<%@page import="com.loyal.loyalerp.basedata.company.model.GyCompany"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../../header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body style="align: center;">
	<div style="margin-top: 10px; margin-left: 30px;">
		<form id="manage-form" action="">
			<div style="margin-left: 40px;">
				<label for="jobcode">公司编号:</label> <input type="text"
					style="width: 120px; height: 28px;" class="ui-input"
					id="companycode" name="companycode"> <label for="jobcode">公司名称:</label>
				<input type="text" style="width: 120px; height: 28px;"
					class="ui-input" id="companyname" name="companyname"><br /><br />
				<label for="jobcode">英文名称:</label> <input type="text"
					style="width: 120px; height: 28px;" class="ui-input"
					id="companyengname" name="companyengname"> <label
					for="jobcode">父级公司:</label> <select style="width: 120px"
					name="parentid" id="parentid">
					<option id="0" value="0">无</option>
					<%
						List<GyCompany> companys = (List<GyCompany>) request.getAttribute("companys");
						Iterator it = companys.iterator();
						while (it.hasNext()) {
							GyCompany company = (GyCompany) it.next();
					%>
					<option id="<%=company.getId()%>" value="<%=company.getId()%>"><%=company.getCompanyname()%></option>
					<%
						}
					%>

				</select><br /> <br />
				<label for="jobcode">负&nbsp;&nbsp;责&nbsp;&nbsp;人:</label> <input
					type="text" style="width: 120px; height: 28px;" class="ui-input"
					id="principal" name="principal"> <label for="jobcode">联系电话:</label>
				<input type="text" style="width: 120px; height: 28px;"
					class="ui-input" id="telephone" name="telephone"></br><br /> <label
					for="jobcode">传&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;真&nbsp;&nbsp;:</label>
				<input type="text" style="width: 120px; height: 28px;"
					class="ui-input" id="fax" name="fax"> <label for="jobcode">公司地址:</label>
				<input type="text" style="width: 120px; height: 28px;"
					class="ui-input" id="address" name="address"></br><br /> <label
					for="jobcode">公司官网:</label> <input type="text"
					style="width: 120px; height: 28px;" class="ui-input" id="website"
					name="website"> <label for="jobcode">&nbsp;状&nbsp;&nbsp;&nbsp;&nbsp;态&nbsp;&nbsp;:<select
					style="width: 120px" name="active" id="active">
						<option id="1" value="1">可用</option>
						<option id="0" value="0">不可用</option>
				</select></br>
			</div>
		</form>
	</div>

	<script type="text/javascript">
		var api = frameElement.api;
		var operate = api.data.operate;
		var rowid = api.data.rowid;
		var rowdata = api.data.rowdata;
		var CallBack = api.data.callback;
		$(function() {
			initPopBtns();
			if (operate == "edit") {

				
				var all_options = document.getElementById("parentid").options;
				for (i = 0; i < all_options.length; i++) {
					if (all_options[i].id == rowdata.parentid) // 根据option标签的ID来进行判断  测试的代码这里是两个等号
					{
						all_options[i].selected = true;
					}
					if (rowid == all_options[i].id) // 根据option标签的ID来进行判断  测试的代码这里是两个等号
					{
						
						all_options.remove(i);
					}
					
				}
				//document.getElementById('parentid').disabled = true;
				$("#companycode").val(rowdata.companycode);
				$("#companyname").val(rowdata.companyname);
				$("#companyengname").val(rowdata.companyengname);
				//$("#parentid").val(rowdata.parentid);
				$("#codelevel").val(rowdata.codelevel+"级公司");
				if(rowdata.endflag==0)
				$("#endflag").val("非末级公司");
				else
				$("#endflag").val("末级公司");
				$("#principal").val(rowdata.principal);
				$("#telephone").val(rowdata.telephone);
				$("#fax").val(rowdata.fax);
				$("#address").val(rowdata.address);
				$("#website").val(rowdata.website);
				all_options = document.getElementById('active').options;
				for (i = 0; i < all_options.length; i++) {
					if (all_options[i].id == rowdata.active) // 根据option标签的ID来进行判断  测试的代码这里是两个等号
					{
						all_options[i].selected = true;
					}
				}
			
			}
		})
		function initPopBtns() {
			var btnname = "add" == operate ? [ "保存", "关闭" ] : [ "确定", "取消" ];
			api
					.button(
							{
								id : "confirm",
								name : btnname[0],
								focus : true,
								callback : function(e) {
    
									if (operate == "add") {
										$
												.ajax({
													url : '${pageContext.request.contextPath}/company/add',
													type : 'POST',
													dataType : "json",
													data : $("#manage-form")
															.serialize(),
													async : false,
													success : function(data) {
														if (data.status == 200) {
															parent.Public
																	.tips({
																		content : "新增成功"
																	})
															CallBack();
														} else {
															parent.Public
																	.tips({
																		type : 1,
																		content : "新增失败:"
																				+ data.message
																	})
														}
													}
												});
									} else {
										$
												.ajax({
													url : '${pageContext.request.contextPath}/company/edit',
													type : "POST",
													dataType : "json",
													data : "id="+rowid+"&"+$("#manage-form").serialize(),
													async : false,//同步,坑爹啊。。
													success : function(data) {
														if (data.status == 200) {
															parent.Public
																	.tips({
																		content : "修改成功"
																	})
															CallBack();
														} else {
															parent.Public
																	.tips({
																		type : 1,
																		content : "修改失败:"
																			+ data.message
									
																	})
														}
													}
												});
									}
								}
							}, {
								id : "cancel",
								name : btnname[1]
							})
		}
	</script>
</body>
</html>